<template>
  <highcharts :options="chartOptions"></highcharts>
</template>

<script setup>
import { onMounted, ref } from "vue";
import { get_echarts } from "../api/ecgartsAPI";

const cookie = ref([]);
const chartOptions = ref({});

onMounted(async () => {
  if (!localStorage.getItem("zwj1")) {
    const res = await get_echarts("keyword_popular", "KeywordPopular", 15);
    localStorage.setItem(
      "zwj1",
      JSON.stringify(res.data).replace(/keyword_name/g, "name")
    );
  }
  cookie.value = JSON.parse(
    localStorage.getItem("zwj1").replace(/keyword_count/g, "weight")
  );

  chartOptions.value = {
    series: [
      {
        type: "wordcloud",
        data: cookie.value,
      },
    ],
    title: {
      text: "词云图",
    },
  };
});
</script>

<style scoped></style>
